package com.szeldon.pj.jps.qres;

public class RealResult extends AbstractQueryResult {

	private double real;

	/**
	 * 
	 * @param real
	 */
	public RealResult(double real) {
		this.real = real;
	}

	public double getReal() {
		return real;
	}

	@Override
	public String toString() {
		return "real(" + real + ")";
	}

	@Override
	public int compareTo(AbstractQueryResult result) {
		if (result instanceof IntegerResult || result instanceof RealResult) {
			double resultDouble = 0;
			if (result instanceof IntegerResult) {
				resultDouble = ((IntegerResult) result).getInteger();
			} else {
				resultDouble = ((RealResult) result).getReal();
			}
			if (real < resultDouble) {
				return -1;
			} else if (real == resultDouble) {
				return 0;
			} else {
				return 1;
			}

		} else {
			throw new IllegalStateException("Real result can't be compared with " + result.getClass().getName()
					+ " result.");
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj.getClass().equals(this.getClass())) {
			RealResult objResult = (RealResult) obj;
			if (real == objResult.getReal()) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

}
